package com.dongnao.barry.ls38_rxjavaopertor;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.dongnao.barry.ls38_rxjavaopertor.rxjava.Function;
import com.dongnao.barry.ls38_rxjavaopertor.rxjava.Obserable;
import com.dongnao.barry.ls38_rxjavaopertor.rxjava.ObservableOnSubscribe;
import com.dongnao.barry.ls38_rxjavaopertor.rxjava.Observer;


public class MainActivity extends AppCompatActivity {

    private static final String TAG = "david";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//

//        1  rxjava   遇到了   鲁班表达式


        /**
         *   Observer1 观察者 ---> 发射器 -----》subecribleOnIO ------》 subscribleMain ------》  OnSubscribleLift  -----》  ObservableOnSubscribe
         *
         */

        new Thread(){
            @Override
            public void run() {
                Obserable.create(new ObservableOnSubscribe<String>() {
                    //            Observer<? super String> observer 农民工
                    @Override
                    public void subscribe(final Observer<? super String> observer) {
//                隐士的递归   1  事件订阅 的开始    2  事件通知的开始     内容
                        observer.onNext("http:www.dongnbao/head.png");//1 会 订阅  不会 2

                        Log.i(TAG, "subscribe: 1  ");
                    }
                }).subscribleMain().subecribleOnIO().map(new Function<String, Bitmap>() {
                    @Override
                    public Bitmap apply(String s) {
                        Log.i(TAG, "apply:    2 "+s);//2
                        return Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
                    }
                }).subscrible(new Observer<Bitmap>() {
                    @Override
                    public void onNext(Bitmap bitmap) {
                        Log.i(TAG, "onNext: 3  "  +bitmap);//3
                        Log.i(TAG, "onNext: "+ Thread.currentThread().getName());

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
            }
        }.start();


    }
}
